

Vue.createApp({
    // 定义组件
    components:{
    },
    // 初始化
    setup(){
        // reactive定义变量运行存储
        // toRefs将数据返回
        const {
            reactive, toRefs
        } = Vue
        // 定义变量，即所需数据
        const state = reactive({
            user: {},
            state: false,
            tip: '请输入提现金额'
        })
        $.get("/loginUser", function(data){
            console.log(data);
            state.user = data
        });
        // 返回数据
        return {
            ...toRefs(state)
        }
    },
    methods:{
        withdrawal(){
            let money = $('#wallet input[name="withdrawal"]').val()
            console.log("接收信息：" + money);
            let reg = /\d+/g
            if (!String(money).match(reg)) {
                swalError("提现失败", "提现金额必须是数字")
                return
            }
            if (money < 10) {
                swalError("提现失败", "提现金额至少是10元")
                return
            }
            money = this.user.balance - money
            if (money < 0) {
                swalError("提现失败", "提现金额不足")
                return
            }
            get("/withdrawal/" + money)
            swalSuccess("提现成功", "提现会在 3-5 个工作日内到账")
            this.user.balance = money
            $('#wallet input[name="withdrawal"]').val('')
        },
        setState(state){
            this.state = state
        }
    }
    // 绑定app
}).mount("#wallet")